package homework;

import java.util.Arrays;

public class Test05 {
    public static void main(String[] args) {
        //- 定义数组，存入多个字符串。
        //- 删除长度大于5的字符串，打印删除后的数组。
        String[] arr = {"he","world","java11","你好哇111","我不好","非常不错"};
        System.out.print(Arrays.toString(arr));
        int index = 0;
        //遍历数组找出长度大于5的字符串，赋值为空
        for (int i = 0; i < arr.length; i++) {
            if (arr[i].length() > 5) {
                arr[i] = null;
                index++;
            }
        }
        System.out.println("index = " + index);
        String[] arr1 = new String[arr.length-index];
        //把数组中不为空的字符串打印出来
        int j = 0;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null) {
                arr1[j] =  arr[i];
                j++;
            }
        }
        System.out.println(Arrays.toString(arr1));
        //有没有别的方法，能不能不用循环

    }
}
